﻿using System;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace ASPNETVN.PORTAL.Components.UI.DataTypes
{
    public class BooleanDataType : BaseDataType
    {
        protected new string _InnerValue = "False";

        public BooleanDataType()
        {
            this._InnerDataType = PropertyDataType.Boolean;
            this._InnerControl = new CheckBox();
        }

        public override string Value
        {
            get { return (this._InnerValue); }
            set { this._InnerValue = bool.Parse(value).ToString(); }
        }

        public override Control EditControl
        {
            get
            {
                if (this._InnerControl == null)
                {
                    this._InnerControl = new CheckBox();
                }

                ((CheckBox)this._InnerControl).Checked = bool.Parse(Value);
                return this._InnerControl;
            }
            set
            {
                if (value.GetType().Name == "CheckBox")
                {
                    this._InnerControl = value;
                    Value = ((CheckBox)this._InnerControl).Checked.ToString();
                }
                else
                    throw new ArgumentException("A CheckBox values is required");
            }
        }

        public override string Description
        {
            get { return "Boolean"; }
        }
    }
}